<?php
if ( ! defined('BASEPATH')) exit('No direct script access allowed');

	
	/*
	* return http 304 given time is same
	*/
	function http_not_modified($content_last_modified_time) 
	{
		if (array_key_exists('HTTP_IF_MODIFIED_SINCE', $_SERVER))
		{
			if ($content_last_modified_time <= strtotime(substr($_SERVER['HTTP_IF_MODIFIED_SINCE'], 0, -4)) ) 
			{
				header("HTTP/1.1 304 Not Modified");
				exit; 
			}
		}
	}
	
	/*
	* set http cache headers
	*/
	function set_http_cache_headers($content_last_modified_time, $cache_age_time) 
	{
		header("Cache-Control: public, maxage=$cache_age_time");
		header('Expires: ' . date('D, d M Y H:i:s', time()+$cache_age_time) . ' GMT');
		header('Last-Modified: ' . date('D, d M Y H:i:s', $content_last_modified_time) . ' GMT');
		header('Pragma:');
	}
	
	
	function process_template_string($string, $vars) 
	{
        extract($vars, EXTR_OVERWRITE); 
        ob_start(); 
        eval('echo ' . $string .';' );
        $contents = ob_get_contents(); 
        ob_end_clean();  
        return $contents;

    }
	
	function process_html_meta(&$html_meta, &$html_meta_vars) 
	{
		$html_meta['page_title'] = process_template_string($html_meta['page_title'], $html_meta_vars);
		$html_meta['meta_keywords'] = process_template_string($html_meta['meta_keywords'], $html_meta_vars);
		$html_meta['meta_description'] = process_template_string($html_meta['meta_description'], $html_meta_vars);
	}
	
	function get_product_url(&$product)
	{
		$post_date = new DateTime($product->post_date); 
		return  base_url() . $product->slug_product_title. '-' .date_format($post_date, 'Y_d_' ) . $product->product_id . '.htm';
	}

	function get_category_url(&$category, $page = 1)
	{
		return base_url() . 'category/' . $category->slug_parent_category_name . (empty($category->slug_parent_category_name) ? '' : '/') . $category->slug_category_name . '/page/'.$page.'/';
	}
	
	function dataCleasing($data){
		$data = strip_tags ($data); // remove HTML Tags
		// remove Incorrect encoding characters
		$data = preg_replace ( '/[^(\x20-\x7F)]*/', "", $data ); 
		$data = str_replace ( "\n", "", $data );//remove Enter
		$data = str_replace ( ",", "", $data );//remove Comma
		$data = str_replace ( "\t", "", $data );//remove TAB
		$data = str_replace ( "\r\n", "", $data );//remove Enter
		$data = trim($data);
		return $data;
	}
	
?>
